#

| Chapter 47 |

# 47. C Shell Programming...NOT

Contents:
Why Not?
C Shell Programming Considered Harmful
Conditional Statements with if
C Shell Variable Operators and Expressions
Using C Shell Arrays
Quick Reference: C Shell switch Statement

## 47.1 Why Not?

We use the C shell for many of the interactive examples in this book. History, aliases, and so forth make it far superior to the original Bourne shell for interactive use. (The newer Korn Shell combines features from both. And bash adds even more.) However, csh has some major drawbacks when it comes to shell programming.

Tom Christiansen explains some of the reasons in his famous tract "C Shell Programming Considered Harmful," which we've included as article 47.2. If you find yourself bristling at the tone of this article, remember that it was originally posted to Usenet (1.33). It is an example of that art form known colloquially as a "flame." As flames go, this is actually fairly mild.

We agree with most of Tom's criticisms, and make no attempt to teach C shell programming in this book. We do however include a few quick-reference style articles on constructs that we use in articles about the C shell's setup files (2.2), since they are in effect nothing but C shell programs read when the shell starts up. Specifically, we cover the syntax of if (47.3) and switch (47.6) statements. We explain how to set and use C shell arrays (47.5)- a nice C shell feature that, we admit `:-)`, the Bourne shell is missing. (The foreach (9.11) loop, covered in another chapter, could be put in this chapter, too.) C shell expressions (47.4) (like `$?prompt`) can be used in if, switch, and foreach.

- TOR, JP

46.10 A Portable echo Command |  | 47.2 C Shell Programming Considered Harmful